import type { EChartsOption } from "echarts";

export async function getOption(echarts): Promise<EChartsOption> {
	let colorList = ['#468FF7', '#00FED2', '#FFD37A','#468FF7', '#00FED2', '#FFD37A']
	let result = [
		{name:'0-14岁',value:25},
		{name:'5-14岁',value:55},
		{name:'15-44岁',value:85},
		{name:'45-59岁',value:65},
		{name:'≥60岁',value:45},
		{name:'未填写',value:85},
	]
	return  {
		color:colorList,
		backgroundColor: '#000416',
		tooltip: {
			show: true,
			trigger: 'item',
			padding: [8, 15],
			backgroundColor: 'rgba(12, 51, 115,0.8)',
			borderColor: 'rgba(3, 11, 44, 0.5)',
			textStyle: {
				color: 'rgba(255, 255, 255, 1)'
			},
		},
		legend: {
			show: false,
		},
		grid: {
			left: '200',
			right: '16%',
			top: '15%',
			bottom: '8%',
		},
		xAxis: [
			{
				splitLine: {
					show: false,
				},
				type: 'value',
				show: false,
			},
		],
		yAxis: [
			{
				splitLine: {
					show: false,
				},
				axisLine: {
					show: false,
				},
				type: 'category',
				axisTick: {
					show: false,
				},
				inverse: true,
				data: result.map((item)=>item.name),
				axisLabel: {
					color: '#fff',
					fontSize: 12,
					margin: 10,
				},
			},
			{
				type: 'category',
				inverse: true,
				axisTick: 'none',
				show: true,
				axisLabel: {
					color: '#fff',
					fontSize: 12,
					formatter: function (value) {
						return value + '%';
					},
				},
				data: result.map((item)=>item.value),
			},
		],
		series: [
			{
				name: '率',
				type: 'bar',
				barWidth: 10, // 柱子宽度
				showBackground: true,
				backgroundStyle: {
					color:'#194B72',
				},
				label: {
					show: false,
				},
				data: result.map((item,index)=>{
					return{
						name:item.name,
						value:item.value,
						itemStyle:{
							color:{
								type: "linear",
								x: 0,
								y: 0,
								x2: 1,
								y2: 1,
								colorStops: [
									{
										offset: 0,
										color: "#0F1F45",
									},
									{
										offset: 1,
										color: colorList[index],
									},
								],
							}
						}
					}
				}),
			},
			{
				name: "外圆",
				type: "scatter",
				emphasis: {
					scale: false,
				},
				symbol: "rect",
				symbolSize: [5,16],
				itemStyle: {
					color: '#FFF',
					shadowColor: "rgba(255, 255, 255, 0.5)",
					shadowBlur: 5,
					borderWidth: 1,
					opacity: 1,
				},
				z: 2,
				data: result,
				animationDelay: 500,
			},
		],
	};
}
